<!DOCTYPE html>
<html lang="zh-cn" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script src="/js/jquery.js"></script>
    <script src="/js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="/element-ui/lib/index.js"></script>

</head>
<body>
<div class="panel admin-panel" id="bannerListDiv">
    <div class="panel-head"><strong class="icon-reorder">评论列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
    <div class="padding border-bottom">
        <form>
            <ul class="search" style="padding-left:10px;">
               <!-- <li> <a class="button border-main icon-plus-square-o" href="/category_add.html">添加评论</a> </li>-->
                <li>搜索：</li>
                <li>
                    <input type="text" placeholder="请输入搜索评论"  class="input" style="width:250px; line-height:17px;display:inline-block" v-model="keyword"/>
                    <a  class="button border-main icon-search" @click="findByPage"> 搜索</a></li>
            </ul>
        </form>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th width="5%">选择</th>
            <th>id</th>
            <th>电影名</th>
            <th width="30%">评论</th>
            <th width="310">操作</th>
        </tr>
        <form >
            <tr v-for="comment in pagination.list">
                <td style="text-align:left; padding-left:10px;"><input type="checkbox" name="ids" :value="comment.id" v-model="ids"/></td>
                <td>{{comment.id}}</td>
                <td v-for="movie in moviesList" v-show="movie.id==comment.moviesId">《{{movie.title}}》</td>
                <td>{{comment.content}}</td>
                <td>
                    <div class="button-group">
                        <a class="button border-main" href=""><span class="icon-edit"></span>修改</a>
                        <a class="button border-red" href="javascript:" @click="deleteById(comment.id)">
                            <span class="icon-trash-o"></span> 删除</a>
                    </div>
                </td>
            </tr>

        </form>
        <tr>
            <td colspan="7" style="text-align:left;padding-left:20px;">
                <a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" @click="deleteIds()"> 批量删除</a>
                <span>总记录数：{{pagination.total}}</span>
            </td>
        </tr>
        <tr>
            <!--添加框-->
            <td colspan="8">

                <div class="pagelist">
                    <!--分页组件-->
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.pageNum"
                            :page-size="pagination.pageSize"
                            :total="pagination.total"
                            background
                            layout="prev, pager, next">
                    </el-pagination>
                </div>
            </td>
    </table>
</div>
<script>
    const app = new Vue({
        el:'#bannerListDiv',
        data:{
            pagination: { // 分页对象
                pageNum: 1,
                pageSize: 5,
                total: 20,
                list: []
            },
            keyword:'',//关键字搜索
            ids:[], //批量删除数组
            moviesList:[],
        },
        methods:{
            //分页查询评论
            findByPage(){
                axios.get('http://127.0.0.1:8081/comment/findByPage',{
                    params:{
                        pageNum:this.pagination.pageNum,
                        pageSize:this.pagination.pageSize,
                        keyword:this.keyword
                    }
                }).then(resp=>{
                    this.pagination=resp.data;
                })
            },
            //当前页改变时调用的方法
            handleCurrentChange(pageNum) {
                //将最新页码赋值给分页对象的当前页码
                this.pagination.pageNum = pageNum;
                //重新发起分页请求
                this.findByPage();
            },
            //改变每页大小时调用的方法
            handleSizeChange(pageSize) {
                //将最新的每页大爱小赋值给分页对象的当前页码
                this.pagination.pageSize = pageSize;
                //重新发起分页请求
                this.findByPage();
            },
            //查询所有电影
            findAllMovies(){
                axios.get('http://127.0.0.1:8081/movies/findAll').then(resp=>{
                    this.moviesList=resp.data;
                })
            },
            //删除单个
            deleteById(id){
                axios.delete('http://127.0.0.1:8081/comment/deleteById?id='+id).then(resp=>{
                    if (resp.data=='ok'){
                        alert('删除成功');
                        //重写查
                        this.findByPage();
                    }
                })
            },
            //批量删除
            deleteIds(){
                axios.delete('http://127.0.0.1:8081/comment/deleteIds?ids='+this.ids).then(resp=>{
                    if (resp.data=='ok'){
                        alert('删除成功');
                        //重写查
                        this.findByPage();
                    }
                })
            }
        },
        created(){
            this.findByPage();
            this.findAllMovies();
        }
    })
</script>
<script src="/js/verify.js"></script>
</body>
</html>